package edu.chl.dat255.bluebanana.utils;

import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

public class SystemListener extends PhoneStateListener {
	private static boolean isAutoRespond;
	private static String message = " ";

	@Override
	public void onCallStateChanged(int state, String incomingNumber) {
		// This method gets the incoming number and
		// it is then retrieved by the PhoneCallReceiver class

		switch (state) {
		case TelephonyManager.CALL_STATE_IDLE:
			Log.d("DEBUG", "IDLE");
			break;
		case TelephonyManager.CALL_STATE_OFFHOOK:
			Log.d("DEBUG", "OFFHOOK");
			break;
		case TelephonyManager.CALL_STATE_RINGING:
			Log.d("DEBUG", "RINGING");

			if (isAutoRespond) {
				Message.sendMessage(incomingNumber, message);
			}
			
			break;
		}
	}

	public static void setAutoRespond(boolean isAutoRespond) {
		SystemListener.isAutoRespond = isAutoRespond;
	}
	
	public static void setMessage(String message) {
		SystemListener.message = message;
	}
}
